package GUI;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.util.List;
import java.awt.Toolkit;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

import DataObjects.Recipe;

/**
 * Class for display of  menu of pressed button on the main page 
 * @author Andrey,Igor
 *
 */

public class PfGeneral_menu1 extends JPanel{
	
	private Dimension screenSize;
	private MainMenu mainMenu;
    private Vector<Recipe> recipe;  
    private String nameMenu;
    private JPanel panel_menu;
  //  private int recipe_quantity=0;
    private int x;
	private int y;
	
	
	public  PfGeneral_menu1(MainMenu mm,Vector<Recipe> theRecipes,String nameMenu )
	{
		super();
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		this.nameMenu=nameMenu;
		this.mainMenu=mm;
		this.recipe=theRecipes;
		initialize();
	}
	
	private void	initialize()
	{
		x=screenSize.width;
		y=screenSize.height;
		
		//-----used for based labels proportion display
		y=y/100;
		this.add(getPanelMenu());
	
	}
	
	
	private  JPanel getPanelMenu()
	{
		
		int j=0;
		int i=0;
		int sign=0;
		panel_menu=new JPanel();
		panel_menu.setLayout(null);
		int role=0;
		//----Nazvanie menu sverhu
		JLabel nameMenuThis = new JLabel(nameMenu);	  
		nameMenuThis.setHorizontalAlignment(SwingConstants.CENTER);  
    	nameMenuThis.setForeground(new Color(160, 82, 45));
    	nameMenuThis.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 50));
    	TextLayout tl1 = new TextLayout(nameMenu,new Font("Tahoma", Font.BOLD | Font.ITALIC, 50) , new FontRenderContext(null, true, true));
    	nameMenuThis.setBounds(5*x/11, y, ((int) tl1.getBounds().getCenterX())*2+10, (int) tl1.getBounds().getHeight()+10);
    	panel_menu.add(nameMenuThis);
    	y=y+(((int) tl1.getBounds().getHeight())*(2));
		
	    	    
	    		
    	List<Integer> a = new ArrayList<Integer>();
    	for ( i=0;i<recipe.size();i++)
    		a.add(Integer.parseInt((String) recipe.get(i).getRole()));
    	    	 
    	 Collections.sort(a);
    	 
    	 for ( i=0;i<recipe.size();i++)
    	 {
    	 for ( j=0;j<recipe.size();j++)
    	     {
    		      if(Integer.parseInt((String) recipe.get(j).getRole())==a.get(i))
    		      {
    		    	   JLabel item_1 =new JLabel();
    			       item_1.setHorizontalAlignment(SwingConstants.RIGHT);  
    			       item_1.setForeground(new Color(150, 100, 153));
    			       item_1.setFont(new Font("Tahoma", Font.BOLD | Font.PLAIN, 15));
    			       String text = (String) recipe.get(j).getName();
    			       
    			        //---------Pomogaet uznat zaranee razmer teksta  chtobi podstroit razmer leibla avtomatom--->TextLayout(nash tekst,nash shrift,...)
    			       TextLayout tl = new TextLayout(text,new Font("Tahoma", Font.BOLD | Font.PLAIN, 15) , new FontRenderContext(null, true, true));
    			       item_1.setText((String) recipe.get(j).getName());
    			       
    			       item_1.setBounds(5*x/11, y, x/9, (int) tl.getBounds().getHeight()+4);
    			       y=y+28;
    			       	     
    			       panel_menu.add(item_1);
    			      
    			       
    		      }
    	     }
    	 }	
	    	
	       
	       
	       //---posle rasstanovki leyblov ustanavlivaem leybl s zenoy menu
	       JLabel priceMenu =new JLabel();
	       priceMenu.setForeground(new Color(160, 82, 45));
	       priceMenu.setFont(new Font("Tahoma", Font.BOLD | Font.PLAIN, 20));
	       String text = (String) recipe.get(0).getPrice()+" ש''ח ";
	       TextLayout tl = new TextLayout(text,new Font("Tahoma", Font.BOLD | Font.PLAIN, 20) , new FontRenderContext(null, true, true));
	       priceMenu.setText((String) recipe.get(0).getPrice()+" ש''ח ");
	       priceMenu.setBounds(5*x/10, y+15, ((int) tl.getBounds().getCenterX())*2+4, (int) tl.getBounds().getHeight()+4);
	      
	       panel_menu.add(priceMenu);
	       return panel_menu;
	}
}
